package ee.helmesWorkTest.frontend.controller;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import ee.helmesWorkTest.GeneralConstants;
import ee.helmesWorkTest.frontend.controller.menucontrollers.MenuController;
import ee.helmesWorkTest.frontend.controller.menucontrollers.PersonSectorMenuController;


@WebServlet("/FrontController")
public class FrontController extends HttpServlet 
{
	private static final long serialVersionUID = 1L;
	private Logger logger = Logger.getLogger(FrontController.class);

    public FrontController()
    {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		request.setCharacterEncoding(GeneralConstants.ENCODING_UTF8);
		response.setContentType(GeneralConstants.CONTENT_TYPE_HTML_UTF8);
		
		ViewManager viewManager = new ViewManager();
		String view = "insertPersonSectorInvolvementPage";
		ServletContext servletContext = getServletConfig().getServletContext();
		MenuController menuController = new PersonSectorMenuController();
		if (menuController != null && !menuController.equals(""))
		{
			view = menuController.service(request, response);
		}
		logger.info("Vaateks on: " + view);
		viewManager.navigate(view, request, response, servletContext);
	}
}
